﻿using PrismViewModel.ViewModels;
using PrismViewModel.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace PrismViewModel
{
    public class Startup : PrismBootstrapper
    {
        protected override DependencyObject CreateShell()
        {
            return Container.Resolve<LoginViewView>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {

        }

        protected override void ConfigureViewModelLocator()
        {
            base.ConfigureViewModelLocator();
            // 1、配置默认的匹配规则
            ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver(ViewTypeToViewModel);

            // 2、明确制定特定View与ViewModel关系
            ViewModelLocationProvider.Register<LoginViewView, LoginViewModel>();
        }

        private Type? ViewTypeToViewModel(Type type)
        {
            var vmName = type.FullName.Replace(".Views.", ".ViewModels.");
            vmName = vmName.EndsWith("View") ? vmName + "Model" : vmName + "ViewModel";
            return Type.GetType(vmName);
        }
    }
}
